package com.kfm.springboot.test;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.kfm.springboot.domain.SysMenu;
import com.kfm.springboot.domain.TreeMenu;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

public class Sorted {

    public static void main(String[] args) {
        List<String> list = new ArrayList<>();

        list.add("b");
        list.add("c");
        list.add("a");

        System.out.println(list);

        List<String> collect = list.stream().sorted((o1, o2) -> o1.compareTo(o2)).collect(Collectors.toList());


        System.out.println(collect);
    }


    @Test
    public void json(){
        SysMenu menu = new SysMenu();

        menu.setId(1);
        menu.setMenuName("用户管理");
        menu.setParentMenu(0);
        menu.setPath("/user");
        menu.setStatus(3);
        menu.setSort(111);

        JsonMapper jsonMapper = new JsonMapper();

        try {
            String string = jsonMapper.writeValueAsString(menu);
            System.out.println(string);

            TreeMenu treeMenu = jsonMapper.readValue(string, TreeMenu.class);
            System.out.println(treeMenu);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
    }
}
